var api = require('../../utils/api.js');
var app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        id:'',
        show:0,
        score:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            id:options.id
        })
        this.gettestbyid(options.id);
    },

    gettestbyid(id){

        var that=this;
        api.post({
            url: 'video/gettestbyid',
            data: {id:id},
            success: data => {
                console.log(data);
                var list=data.data.videos;
                that.setData({
                    lists:data.data.list,
                    show:data.data.show,
                    score:data.data.score
                })

                wx.setNavigationBarTitle({
                    title: data.data.title 
                  })
              
            }
        });

    },

    formSubmit(e){
        console.log(e.detail.value);
        var that=this;
        var value=e.detail.value;
        var lists=this.data.lists;
        var number=0;
        var id=this.data.id;

        lists.forEach(function(item,index){

            if(item.successlist==value[index]){
                number=number+1
            }
         

        })

        console.log(number);

        wx.showModal({

        title: '提示',
            content: '本次您得分'+number+' 是否需要提交？',
            success (res) {
                if (res.confirm) {
                  
                    api.post({
                        url: 'video/submitdf',
                        data: {id:id,number:number},
                        success: data => {
                            console.log(data);
                            wx.showToast({
                              title: data.msg,
                              icon:'none'
                            })
                        }
                    });
                } else if (res.cancel) {
                
                }
            }
        })



    }
})